package automateWebElements;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;

public class End2EndCase {
    public static void main(String[] args) {
        FirefoxDriver driver = new FirefoxDriver();
        final String ALERT_MESSAGE = "Family and Friends discount is applicable for a minimum of 4 passenger (excluding infant) on a single booking. Terms and conditions apply.";
        driver.get("https://rahulshettyacademy.com/dropdownsPractise/");

        driver.findElementByXPath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']").click();
        driver.findElementByXPath("//a[@value='DEL']").click();
        driver.findElementByXPath("//div[@id='glsctl00_mainContent_ddl_destinationStation1_CTNR'] //a[@value='MAA']").click();
        driver.findElementByCssSelector(".ui-state-default.ui-state-highlight").click();
        if (driver.findElementById("Div1").getAttribute("style").contains("0.5")) {
            System.out.println("Element is disabled");
            Assert.assertTrue(true);
        } else {
            System.out.println("Element is enabled");
            Assert.assertTrue(false);
        }

        WebElement staticDropDown =  driver.findElementById("ctl00_mainContent_DropDownListCurrency");
        Select dropdown = new Select(staticDropDown);
        dropdown.selectByVisibleText("USD");

        driver.findElementByXPath("//*[@id=\'divpaxinfo\']").click();
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 2; i++) {
            driver.findElementByXPath("//*[@id=\'hrefIncAdt\']").click();
        }
        driver.findElementByXPath("//*[@id=\'btnclosepaxoption\']").click();


        driver.findElementByXPath("//input[@id='ctl00_mainContent_chk_friendsandfamily']").click();

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        driver.findElementByXPath("//input[@value='Search']").click();
        String currentAlertMessage = driver.switchTo().alert().getText();
        Assert.assertEquals(ALERT_MESSAGE,currentAlertMessage);
        driver.switchTo().alert().accept();

    }
}
